// pages/informationSet/informationSet.js
const $ = require("../../utils/util.js")
import Dialog from '@vant/weapp/dialog/dialog';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    sets: null,
    mobile: "",
    res: "",
    password: "",
    doublepassword: "",
    text: "获取验证码",
    disab: true,
    name: "",
    cationcode:"",
    loginpass:"",
    newphone:""
  },

  // 返回
  onClickLeft() {
    wx.navigateBack()
  },

  // 2
  fun() {
    if (this.data.mobile != "" & this.data.mobile.length == 11) {
      console.log(11);
      $.axios({
        url: "auth/captcha",
        method: "POST",
        header: {
          "X-Byesame-Token": wx.getStorageSync('token')
        },
        data: {
          mobile: this.data.mobile,
          type: "change-password"
        }
      }).then(res => {
        wx.showToast({
          title: res.data.errmsg,
        })
      }).catch(error => {
        console.log(error);
      })
    }
  },
  fun2() { //点击保存密码
    if (this.data.mobile.length == 11 && this.password != "" && this.data.res) {
      console.log(11);
      $.axios({
        url: "auth/reset",
        method: "POST",
        header: {
          "X-Byesame-Token": wx.getStorageSync('token')
        },
        data: {
          code: this.data.res, //验证码因为获取不到无法写
          password: this.data.password,
          mobile: this.data.mobile,
        }
      }).then(res => {
        wx.showToast({
          title: res.data.errmsg,
        })
      }).catch(error => {
        console.log(error);
      })
    } else {
      wx.showToast({
        title: '请输入必要信息',
      })
    }
  },
  fun3() { //倒数
    if (this.data.mobile, length == 11) {
      let a = 60
      let b = setInterval(() => {
        if (a > 0) {
          this.setData({
            text: `请在${a}秒后重试`,
            disab: true
          })
          a--
        } else {
          this.setData({
            text: `获取验证码`,
            disab: false
          })
          clearInterval(b)
        }
      }, 1000)
    }
  },

  // 保存名称
  authprofile() {
    $.axios({
      url: "auth/profile",
      method: "POST",
      data: {
        nickname: this.data.name
      }
    }).then(res => {
      if (res.data.errno == 0) {
        Dialog.alert({
          message: '保存成功',
        }).then(() => {
          wx.navigateBack()
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      sets: options.set
    })
    if (this.data.sets == 1) {
      this.setData({
        name: options.name
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})